package com.day12.homework;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class AtmoBase {
    private double temperature;
    private double humidity;
    private double wind;

    private boolean isReady = false;
    private int sum = 0;

    public synchronized void put(double t, double h, double w) {
        if (isReady) {
            try {
                wait(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.temperature = t;
        this.humidity = h;
        this.wind = w;
        isReady = true;
        notify();
    }

    public synchronized void get() {
        if (!isReady) {
            try {
                wait(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        sum += 1;
        System.out.println("==== 第 " + sum + " 次读取数据");
        System.out.println("== [" + temperature + " : " + humidity + " : " + wind + "]");
        isReady = false;
        notify();
    }
}
